#include "StdAfx.h"
#include "Effect.h"
#include "Material.h"

VAMPIRE_NAMESPACE_BEGIN

BOOL Effect::initialise( const TString& fileName )
{
	LPD3DXBUFFER errorBuffer = NULL;
	DWORD flag = 0;

#ifdef _DEBUG
	flag = flag | D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION;
#else
	flag = D3DXSHADER_SKIPVALIDATION;
#endif

	D3DXCreateEffectFromFile(
		gpDevice,
		fileName.c_str(),
		NULL, 
		NULL, 
		flag, 
		NULL, 
		&mpData,
		&errorBuffer);
	if (NULL == errorBuffer)
	{
		SAFE_RELEASE(errorBuffer);
		return TRUE;
	}
	else
	{
		char* c = (char*)errorBuffer->GetBufferPointer();
		MessageBoxA(0, c, 0, 0);
		return FALSE;
	}
	
	
}

UINT Effect::begin()
{
	UINT numPasses = 0;
	mpData->Begin(&numPasses, 0);
	return numPasses;
}

void Effect::end()
{
	mpData->End();
}

void Effect::beginPass( UINT id )
{
	mpData->BeginPass(id);
}

void Effect::endPass()
{
	mpData->EndPass();
}

bool Effect::getTechnique()
{
	mhTechnique = mpData->GetTechniqueByName(mTechniqueName.c_str()); 
	return mhTechnique == NULL ? false : true;
}

void Effect::castTechniqueToCurrent()
{
	mpData->SetTechnique(mhTechnique);
}

void Effect::commitChanges()
{
	mpData->CommitChanges();
}

VAMPIRE_NAMESPACE_END
